import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const HomePage(),
    );
  }
}

//有状态组件:如果我们想改变页面中的数据的话这个时候就需要用到statefulwidgetl
class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  int _numCount = 0;
  @override
  Widget build(BuildContext context) {
    // print("_numCount :$_numCount");
    return Scaffold(
      appBar: AppBar(
          title: const Text("P32 statefulw")), //这个加了const 数值加刷新的时候不会重新加载这个标题
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text("$_numCount",
                style: Theme.of(context).textTheme.headlineLarge),
            const SizedBox(height: 60),
            ElevatedButton(
                onPressed: () {
                  setState(() {
                    _numCount++;
                  });
                },
                child: const Text(
                  "增加",
                  style: TextStyle(color: Colors.black45),
                ))
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            _numCount++;
          });
        },
        child: const Icon(Icons.add),
      ),
    );
  }
}


// class HomePage extends StatelessWidget {
//   int countNum = 0;
//   HomePage({super.key});

//   @override
//   Widget build(BuildContext context) {
//     return Scaffold(
//       appBar: AppBar(
//         title: const Text("p32"),
//       ),
//       body: Center(
//         child: Column(
//           mainAxisAlignment: MainAxisAlignment.center,
//           children: [
//             Text(
//               "$countNum",
//               style: Theme.of(context).textTheme.headlineLarge,
//             ),
//             const SizedBox(height: 100),
//             ElevatedButton(
//                 onPressed: () {
//                   countNum++;
//                   print(countNum);
//                 },
//                 child: const Text("增加"))
//           ],
//         ),
//       ),
//     );
//   }
// }
